<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>WebCópias - Manutenção de Departamentos</title>
	<link rel="shortcut icon" href="../assets/image/favicon.ico" />
	<link rel="stylesheet" href="../assets/css/styleDepartment.css" />
</h:head>
<body>
	<p:growl id="resultMessage" showDetail="true" life="4000" />
	<p:layout fullPage="true" styleClass="container">
	
		<p:layoutUnit position="north" size="95" resizable="false" closable="false"	collapsible="false" styleClass="header">
			<ui:include src="/form/header.xhtml"></ui:include>
		</p:layoutUnit>
		
		<p:layoutUnit position="west" size="200" header="Navegação" collapsible="true"	styleClass="menu" style="padding:0 !important;">
			<ui:include src="/form/menu.xhtml"></ui:include>
		</p:layoutUnit>
		
		<p:layoutUnit position="center" styleClass="content" header="Manutenção de Departamentos">
			<h:form id="datatableForm">

				<p:dataTable id="departmentDatatable" emptyMessage="Nenhum departamento cadastrado" var="departments" value="#{department.listDepartments}" widgetVar="departmentsList" styleClass="datatable-department">
					<f:facet name="header">
						<p:commandButton id="btAddDepartment" styleClass="addDepartmentButton"
						update=":formAddDepartment:panelAddDepartment" actionListener="#{department.prepareCreateDepartment}"
						oncomplete="addNewDepartment.show()" value="Adicionar Departamento" icon="ui-icon-circle-plus" 
						title="Adicionar Departamento" />
						
					</f:facet>  
			        <p:column headerText="Código" style="width:15%" styleClass="column-datatable">  
			            <h:outputText value="#{departments.departamentCode}" styleClass="value-datatable"/>  
			        </p:column>  
			  
			        <p:column headerText="Descrição" style="width:20%" styleClass="column-datatable">  
			            <h:outputText value="#{departments.departmentName}" styleClass="value-datatable"/>  
			        </p:column>  
			  
			        <p:column headerText="Chefe do Departamento" style="width:5%" styleClass="column-datatable">  
			            <h:outputText value="#{departments.registration.name}" styleClass="value-datatable"/>  
			        </p:column>  
			        
			        <p:column style="width:5%; text-align:center !important;" styleClass="column-datatable">  
		                <p:commandButton id="btEditDepartment" oncomplete="editDepartment.show()" icon="ui-icon-pencil" update=":formEditDepartment:panelEditDepartment" title="Editar">  
			                <f:setPropertyActionListener value="#{departments}" target="#{department.department}" styleClass="value-datatable"/>  
		           		</p:commandButton>  
	                	<p:commandButton id="btViewDepartment" oncomplete="viewDepartment.show()" update=":formViewDepartment:panelViewDepartment" icon="ui-icon-search" title="Visualisar"> 
		                	<f:setPropertyActionListener value="#{departments}" target="#{department.department}" styleClass="value-datatable"/>  
		            	</p:commandButton>  
		                <p:commandButton id="btDeleteDepartment" oncomplete="confirmationDeleteDepartment.show()" icon="ui-icon-trash" title="Remover">  
			                <f:setPropertyActionListener value="#{departments}" target="#{department.department}" styleClass="value-datatable"/>  
			            </p:commandButton>  
			        </p:column>  
			  
			    </p:dataTable>
			</h:form>
		</p:layoutUnit>
	</p:layout>
	
	<p:dialog header="Alterar Conta" widgetVar="updateAccount" resizable="false" modal="true" showEffect="slide" width="500">
		<h:form prependId="false">
			<h:panelGrid id="infosLivro" columns="2" style="margin-bottom:10px">
				<h:outputLabel for="updateRegistration" value="Matrícula:" />
				<p:inputText value="#{user.loggedUser.registration}" id="updateRegistration" disabled="true" />

				<h:outputLabel for="updateName" value="Nome:" />
				<p:inputText value="#{user.loggedUser.name}" id="updateName" />

				<h:outputLabel for="updatePassword" value="Senha:" />
				<h:inputSecret value="#{user.loggedUser.password}" id="updatePassword" styleClass="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-state-hover" />

				<h:outputLabel for="updateEmail" value="E-mail:" />
				<p:inputText value="#{user.loggedUser.email}" id="updateEmail" required="false" />

				<h:outputLabel for="updatePhoto" value="Foto:" />
				<p:inputText value="#{user.loggedUser.photo}" id="updatePhoto" required="false" />

				<p:commandButton oncomplete="updateAccount.hide()" actionListener="#{user.selfUpdateUser}" update=":resultMessage" value="Salvar" >
					<f:ajax event="click" execute="updateName" render="userMenu" update="userMenu"/>
				</p:commandButton>
			</h:panelGrid>
		</h:form>
	</p:dialog>

	<p:dialog header="Adicionar Departamento" widgetVar="addNewDepartment" resizable="false" modal="true" showEffect="fade" width="600">
		<h:form prependId="false" id="formAddDepartment">
			<h:panelGrid id="panelAddDepartment" columns="2" style="margin-bottom:10px">
				<h:outputLabel for="addCode" value="Código:" />
				<p:inputText value="#{department.department.departamentCode}" id="addCode" size="10"/>

				<h:outputLabel for="addName" value="Nome:" />
				<p:inputText value="#{department.department.departmentName}" id="addName" size="30"/>

				<h:outputLabel for="addBoss" value="Chefe do departamento:" />
				<p:selectOneMenu id="addBoss" value="#{department.selectedBoss}">
					<f:selectItems value="#{department.heads}" />
				</p:selectOneMenu>

				<f:facet name="footer">
					<p:pickList id="departmentsPickList" value="#{department.listDiscipline}" var="departmentList"   
	                itemLabel="#{departmentList.disciplineName}" itemValue="#{departmentList}" converter="disciplineConverter">
	                
	                	<f:facet name="sourceCaption">Disciplinas existentes</f:facet>  
	        			<f:facet name="targetCaption">Disciplinas adicionadas</f:facet>
	        			
	                </p:pickList> 
				</f:facet>

				<f:facet name="footer">
					<p:separator/>
					<p:commandButton actionListener="#{department.createNewDepartment}" oncomplete="addNewDepartment.hide()" 
					update=":datatableForm:departmentDatatable :resultMessage" value="Confirmar" />
				
					<p:commandButton oncomplete="addNewDepartment.hide()" value="Fechar" />
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>

	<p:dialog header="Informações do Departamento" widgetVar="viewDepartment" resizable="false" modal="true" showEffect="fade" width="600">
		<h:form prependId="false" id="formViewDepartment">
			<h:panelGrid id="panelViewDepartment" columns="2" style="margin-bottom:10px">
				<h:outputLabel for="viewCode" value="Código:" />
				<p:inputText value="#{department.department.departamentCode}" id="viewCode" readonly="true" size="10"/>

				<h:outputLabel for="viewName" value="Nome:" />
				<p:inputText value="#{department.department.departmentName}" id="viewName" readonly="true" size="30"/>

				<h:outputLabel for="viewBoss" value="Chefe de departamento:" />
				<p:inputText value="#{department.department.registration.name}" id="viewBoss" readonly="true" size="30"/>

				<h:outputLabel for="dataListDiscipline" value="Disciplinas:" />
				<p:dataList value="#{department.disciplineToList}" id="dataListDiscipline" var="discList" itemType="circle">  
    				#{discList.disciplineName} 
				</p:dataList>

				<f:facet name="footer">
					<p:separator/>
					<p:commandButton oncomplete="viewDepartment.hide()" value="Fechar" />
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
	
	<p:dialog header="Editar Departamento" widgetVar="editDepartment" resizable="false" modal="true" showEffect="fade" width="600">
		<h:form prependId="false" id="formEditDepartment">
			<h:panelGrid id="panelEditDepartment" columns="2" style="margin-bottom:10px">
				<h:outputLabel for="editCode" value="Código:" />
				<p:inputText value="#{department.department.departamentCode}" id="editCode" size="10"/>

				<h:outputLabel for="editName" value="Nome:" />
				<p:inputText value="#{department.department.departmentName}" id="editName" size="30"/>

				<h:outputLabel for="editBoss" value="Limite de cópias:" />
				<p:selectOneMenu id="editBoss" value="#{department.department.registration.name}">
					<f:selectItems value="#{department.heads}" />
				</p:selectOneMenu>
				
				<f:facet name="footer">
					<p:pickList id="editDisciplinePickList" value="#{department.listDiscipline}" var="disciplineList"   
	                itemLabel="#{disciplineList.disciplineName}" itemValue="#{disciplineList}" converter="disciplineConverter">
	                
	                	<f:facet name="sourceCaption">Disciplinas existentes</f:facet>  
	        			<f:facet name="targetCaption">Disciplinas adicionadas</f:facet>
	        			
	                </p:pickList> 
				</f:facet>
				
				<f:facet name="footer">
					<p:separator/>
					<p:commandButton actionListener="#{department.updateDepartment}" oncomplete="editDepartment.hide()" 
					update=":datatableForm:departmentDatatable :resultMessage" value="Comfirmar" />
					<p:commandButton oncomplete="editDepartment.hide()" value="Fechar" />
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
	
	<h:form>  
	    <p:confirmDialog id="confirmDeleteDepartment" message="Deseja remover este departamento?" header="Remover departamento" severity="alert" widgetVar="confirmationDeleteDepartment">  
	        <p:commandButton id="confirmDelete" value="Sim" onclick="confirmDeleteDepartment.hide()" update=":datatableForm:departmentDatatable :resultMessage" actionListener="#{department.deleteDepartment}" />  
	        <p:commandButton id="decline" value="Não" onclick="confirmDeleteDepartment.hide()" />   
	    </p:confirmDialog>  
	</h:form>
</body>
</html>